package com.xzj.springmvc;

import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ProjectName: SpringDemo
 * @Package: com.xzj.springmvc
 * @ClassName: HandleMapping 和 Spring MVC 实现不一样   这里在扫描文件的时候加载并初始化 beanMappings methodMappings
 * @Author: xzj
 * @Description:
 * @Date: 2022/7/13 16:18
 * @Version: 1.0
 */
public class HandlerMapping {

    /**
     * 放全部被 @Controller修饰的bean对象
     */
    private static Map<String,Object> beanMappings = new ConcurrentHashMap<>();

    /**
     * 放全部被RequestMapping修饰的bean方法
     */
    private static Map<String, Method> methodMappings = new ConcurrentHashMap<>();

    public static Object getServerBean(String url) {
        return beanMappings.get(url);
    }

    public static Method getMethod(String url) {
        return methodMappings.get(url);
    }

    public static void setServerBean(String url, Object obj) {
        beanMappings.put(url, obj);
    }

    public static void setMethod(String url, Method method) {
        methodMappings.put(url, method);
    }

    @Override
    public String toString() {
        return "HandlerMapping{}"+beanMappings+"\r\n"+methodMappings;
    }
}

